package com.ihmp.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ihmp.model.Tfloors;
@Repository("FloorDao")
public class FloorDaoImpl implements FloorDao {
	@Autowired
	private SessionFactory sessionFactory;
	@Override
	public void saveOrUpdate(Tfloors floor) {
		sessionFactory.getCurrentSession().saveOrUpdate(floor);
		
	}

	@Override
	public Tfloors findById(Integer id) {
		 return (Tfloors) sessionFactory.getCurrentSession().get(Tfloors.class, id);
	}

	@Override
	public void delete(Tfloors floor) {
		 sessionFactory.getCurrentSession().delete(floor);
		
	}

	@Override
	public List<Tfloors> listFloors() {
		 return (List<Tfloors>) sessionFactory.getCurrentSession().createQuery("from Tfloors").list();
	}

	@Override
	public List<Tfloors> getFloorsFromHotelId(Integer id) {
		String strQuery = "from Tfloors WHERE HotelID =:HotelID  ";
		Query query = sessionFactory.getCurrentSession().createQuery(strQuery);
		query.setParameter("HotelID", id);
		return query.list();
	}

}
